package fnord.illuminati.card.winconditions;

import java.util.LinkedList;
import java.util.Queue;

import fnord.illuminati.Board;
import fnord.illuminati.card.GroupCard;
import fnord.illuminati.card.WinCondition;
import fnord.network.server.Player;

public class GeneralWinCondition extends WinCondition {
	private static final long serialVersionUID = -4711167709717910861L;

	private final int _cardsToWin;
	
	public GeneralWinCondition(Board b) {
		super();
		switch (b.getPlayers().size()) {
		case 1: _cardsToWin = 14; break;
		case 2: _cardsToWin = 13; break;
		case 3: _cardsToWin = 13; break;
		case 4: _cardsToWin = 12; break;
		case 5: _cardsToWin = 10; break;
		case 6: _cardsToWin = 9; break;
		case 7: _cardsToWin = 8; break;
		case 8: _cardsToWin = 8; break;
		default: _cardsToWin = 7; break;
		}
	}
	
	@Override
	public boolean hasWon(Player p) {
		Queue<GroupCard> cards = new LinkedList<GroupCard>();
		cards.add(p.getIlluminati());
		int count = 0;
		while (!cards.isEmpty()) {
			cards.addAll(cards.poll().getChildren());
			count++;
		}
		if (count>=_cardsToWin)
			return true;
		else
			return false;
	}
}
